import { _decorator, Component, Node, Button } from 'cc';
import { BasePanel } from '../../../../scripts/libs/ui/BasePanel';
import { BindButton } from '../../../../scripts/libs/rxjs/cc3/BindButton';
import { LeaderboardScrollView } from './LeaderboardScrollView';
import { NextFrame } from '../../../../scripts/libs/rxjs/cc3/CreatorSchedule';
import { optimizeScrollView } from '../../../../scripts/libs/utils/ScrollView/OptimizeScrollView';
const { ccclass, property } = _decorator;

@ccclass('LeaderboardPanel')
export class LeaderboardPanel extends BasePanel {

    @property(Button)
    closeButton: Button = null;

    @property(LeaderboardScrollView)
    scrollView: LeaderboardScrollView = null;

    useObserves() {
        return [
            BindButton(this.closeButton).subscribe(this.closeButtonClicked.bind(this)),
        ];
    }

    onLoadView(): void {
        NextFrame().subscribe(_ => {
            this.scrollView.open('default', 0);
            optimizeScrollView(this.scrollView.scrollView);
        });
    }

    closeButtonClicked() {
        LeaderboardPanel.CloseProcess(null, 'close');
    }

}

